home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / incl / LEDA.020+881 / hash.h < prev    next >
C/C++ Source or Header  |  1994-08-05  |  2KB  |  72 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  hash.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_HASH_H
  16. #define LEDA_HASH_H
  17.  
  18. //------------------------------------------------------------------------------
  19. // hash dictionary (based on hashing with chaining)
  20. //------------------------------------------------------------------------------
  21.  
  22. #include <LEDA/impl/ch_hash.h>
  23.  
  24. typedef ch_hash_item hash_item;
  25.  
  26.  
  27. template<class keytype, class inftype> 
  28.  
  29. class _CLASSTYPE hash : public ch_hash {
  30.  
  31. int (*hash_ptr)(const keytype&);
  32.  
  33. int  int_type() const { return INT_TYPE(keytype); }
  34.  
  35. int  hash_fct(GenPtr x) const
  36. { return (hash_ptr) ? (*hash_ptr)(ACCESS(keytype,x)) : int(x); }
  37.  
  38. int  cmp(GenPtr x, GenPtr y) const
  39.                     { return compare(ACCESS(keytype,x),ACCESS(keytype,y)); }
  40. void clear_key(GenPtr& x)   const { Clear(ACCESS(keytype,x)); }
  41. void clear_inf(GenPtr& x)   const { Clear(ACCESS(inftype,x)); }
  42. void copy_key(GenPtr& x)    const { x=Copy(ACCESS(keytype,x)); }
  43. void copy_inf(GenPtr& x)    const { x=Copy(ACCESS(inftype,x)); }
  44. void print_key(GenPtr x)    const { Print(ACCESS(keytype,x),cout); }
  45.  
  46. public:
  47.  
  48. hash_item lookup(keytype y)  const { return ch_hash::lookup(Convert(y)); }
  49. int       defined(keytype x) const { return (lookup(x)) ? false : true; }
  50. void      change_inf(hash_item it, inftype i)
  51.                                     { ch_hash::change_inf(it,Convert(i)); }
  52. hash_item insert(keytype y,inftype x)
  53.                                     { return ch_hash::insert(Convert(y),Convert(x));}
  54. void     del(keytype y)            { ch_hash::del(Convert(y)); } 
  55. void     del_item(hash_item it)    { del(key(it)); } 
  56. keytype  key(hash_item it)   const { return ACCESS(keytype,ch_hash::key(it)); }
  57. inftype  inf(hash_item it)   const { return ACCESS(inftype,ch_hash::inf(it)); }
  58.  
  59. hash()                         { hash_ptr=0;}
  60. hash(int (*f)(const keytype&)) { hash_ptr=f;}
  61.  
  62. hash(int s)  : ch_hash(s) { hash_ptr=0;}
  63. hash(int s, int (*f)(const keytype&)) : ch_hash(s) { hash_ptr=f;}
  64.  
  65. ~hash() { clear(); }
  66.  
  67. } ;
  68.  
  69.  
  70. #endif
  71.